layui.use(['laydate','form','table','laytpl','layer'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var laytpl = layui.laytpl;
	var layer = layui.layer;

	//执行一个laydate实例
	laydate.render({
	  	elem: '#start' //指定元素
	});

	//执行一个laydate实例
	laydate.render({
	  	elem: '#end' //指定元素
	});
	
	/*@统计*/
	estimate = function(objData){
		$.post('/finance/finance/estimate', objData, function(data){
			if(data.code !== 1){
				layer.msg(data.msg, {icon: 5});
			}else{
				let getTpl_2 = table_shouru.innerHTML;
				let count2 = document.getElementById('table-shouru');
				laytpl(getTpl_2).render(data.msg.income, function(html){
					count2.innerHTML = html;
				});
				let getTpl_1 = table_zhichu.innerHTML;
				let count1 = document.getElementById('table-zhichu');
				laytpl(getTpl_1).render(data.msg.pay, function(html){
					count1.innerHTML = html;
				});
			}
		})
	}
	estimate()
	/*@查询*/
	form.on('submit(search)',function(data){
		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		estimate(data.field)
        return false
	})
	
});